package com.kingint.web.sys.controller;


import com.kingint.common.unitedresult.K;
import com.kingint.mbg.dto.UmsPermissionNode;
import com.kingint.mbg.group.Insert;
import com.kingint.mbg.group.Update;
import com.kingint.web.domain.Tree;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import com.kingint.web.sys.service.UmsPermissionService;
import com.kingint.mbg.sys.entity.UmsPermission;

import java.util.List;


/**
 * @描述：后台用户权限表控制类
 * @作者: wxh
 * @日期: 2020-09-18
 */
@RestController
@RequestMapping("/umsPermission")
@Api(value = "UmsPermissionController", description = "后台用户权限表")
@CrossOrigin
public class UmsPermissionController extends BaseController{

    @Autowired
    public UmsPermissionService umsPermissionService;

    @ApiOperation("获取用户所有权限列表")
    @GetMapping(value = "/findPermissions")
    public Object findPermissions() {
        List<Tree<UmsPermission>> permissionsByUserId = umsPermissionService.getPermissionsByUserId(getCurrentUser().getId());
        return K.ok().data(permissionsByUserId);
    }
    @ApiOperation("以层级结构返回所有权限")
    @GetMapping(value = "/treeList")
    public Object treeList() {
        List<UmsPermissionNode> permissionNodeList = umsPermissionService.treeList();
        return K.ok().data(permissionNodeList);
    }
}